package lingou.homework.postbar.controller;

import lingou.homework.postbar.controller.proto.resp.Response;
import lingou.homework.postbar.controller.tool.LogPrinter;
import lingou.homework.postbar.exception.SystemException;
import lingou.homework.postbar.service.HelloService;
import lingou.homework.postbar.service.mock.MockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    HelloService helloService;
    @Autowired
    MockService mockService;

    @GetMapping
    Response hello(){
        return Response.ofSuccess(helloService.getAllUsers());
    }

    @GetMapping("/exception")
    Response exception(){
        throw new SystemException("hello exception");
    }
//    @GetMapping
//    String hello(String msg){
//        System.out.println(msg);
//        return "hhhh！";
//    }

    @PostMapping("/gen")
    Response gen(String mock, Integer count, double[] rate) {
        switch (mock){
            case "user": mockService.mockUser(count); break;
            case "pub": mockService.mockPubPost(count); break;
            case "comment": mockService.mockComment(count); break;
            case "comment2": mockService.mockComment2(count); break;
            case "box": mockService.mockBox(count, rate); break;
            case "fixComment": mockService.fixComment(); break;
            case "fixType": mockService.fixType(); break;
            default: Response.ofFailure("unknown");
        }
        return Response.ofSuccess();
    }

}
